package lzit.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class DBUtil{
    public static Connection getCon(){
        try{
            String drivername = "com.mysql.cj.jdbc.Driver";
            String conUrl = "jdbc:mysql://localhost:3306/nieh?serverTimezone=GMT%2B8";
            String username = "root";
            String password = "root";
            Connection con = null;

            Class.forName(drivername);
            con  =  DriverManager.getConnection(conUrl,  username,  password);
            return con;
        }catch(Exception e){
            e.printStackTrace();
        }
        return null;
    }

    public static void release(ResultSet rs, Statement stmt, Connection con){
        if(rs != null){
            try{
                rs.close();
            }catch(Exception e){
                e.printStackTrace();
            }
            rs = null;
        }
        if(stmt != null){
            try{
                stmt.close();
            }catch(Exception e){
                e.printStackTrace();
            }
            stmt = null;
        }

        if(con != null){
            try{
                con.close();
            }catch(Exception e){
                e.printStackTrace();
            }
            con = null;
        }
    }
}